package com.sxpi.user.controller.user;

import com.sxpi.common.result.R;
import com.sxpi.user.controller.BaseController;
import com.sxpi.user.service.useramount.IUserAmountRecordService;
import com.sxpi.user.vo.UserAmountVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 董伟豪
 * @Date: 2022/11/8 21:33
 */
@RestController
@Slf4j
public class UserAmountRecordController extends BaseController {

    @Autowired
    private IUserAmountRecordService userAmountRecordService;

    /**
     * 用户提现
     * @return
     * @paramp loginVo
     */
    @PostMapping("/takemoney")
    public R takeMoney(@RequestBody UserAmountVo userAmountVo){
        return userAmountRecordService.takeMoney(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - 悲观锁
     * @param userAmountVo
     * @return
     */
    @PostMapping("/takemoneypessimism")
    public R takeMoneyPessimismLock(@RequestBody UserAmountVo userAmountVo){
        return userAmountRecordService.takeMoneyPessimismLock(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - 乐观锁
     * @param userAmountVo
     * @return
     */
    @PostMapping("/takemoneyoptimism")
    public R takeMoneyOptimismLock(@RequestBody UserAmountVo userAmountVo){
        return userAmountRecordService.takeMoneyOptimismLock(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - redis不可重入
     * @return
     * @paramp loginVo
     */
    @PostMapping("/takemoneyredis")
    public R takeMoneyRedisLock(@RequestBody UserAmountVo userAmountVo) {
        return userAmountRecordService.takeMoneyRedisLock(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - zookeeper可重入
     * @return
     * @paramp loginVo
     */
    @PostMapping("/takemoneyzookeeper")
    public R takeMoneyZookeeperLock(@RequestBody UserAmountVo userAmountVo) {
        return userAmountRecordService.takeMoneyZookeeperLock(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - zookeeper可重入
     * @return
     * @paramp loginVo
     */
    @PostMapping("/takemoneyredisson")
    public R takeMoneyRedissonLock(@RequestBody UserAmountVo userAmountVo) {
        return userAmountRecordService.takeMoneyRedissonLock(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - redisson不可重入
     * @return
     * @paramp loginVo
     */
    @PostMapping("/takemoneyredissontrylock")
    public R takeMoneyRedissonTryLock(@RequestBody UserAmountVo userAmountVo){
        return userAmountRecordService.takeMoneyRedissonTryLock(userAmountVo);
    }
}
